﻿/****************
* Authored by Zhuo "Wizcas" Chen
* 2018 © Wubi.fun all rights reserved
*****************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class QueueSlots : MonoBehaviour 
{
    readonly Vector3 GLOBAL_OFFSET = Vector3.one * 1000;
    [SerializeField] UIBlock[] slots;

    private void Awake()
    {
        BlockQueue.instance.onQueueChanged += OnQueueChanged;
        Hide();
    }

    public void Show() { gameObject.SetActive(true); }
    public void Hide() { gameObject.SetActive(false); }


    private void OnQueueChanged(BlockQueue q)
    {
        var peek = q.Peek();
        for(int i = peek.Length - 1; i >= 0; i--)
        {
            SetBlock(i, peek[i]);
        }
    }

    void SetBlock(int index, Block block)
    {
        if (index < 0 || index >= slots.Length) return;
        slots[index].block = block;
        slots[index].interactable = index == 0;
        if (block != null) block.isFree = index == 0;
    }

    #region DEV
    [ContextMenu("Gen mock")]
    void GenMock()
    {
        for (int i = 0; i < 5; i++) { BlockQueue.instance.Enqueue("A"); }
    }
    #endregion
}
